home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TDeletePoint.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  13.8 KB  |  374 lines  |  [TEXT/MPS ]

  1. #pragma segment CObj
  2. // **********************************************************************
  3. //    TDeletePointCommand - Methods
  4. // **********************************************************************
  5. // --------------------------------------------------------------------------------------------------
  6. //    Initializing the dragger command .....
  7. // --------------------------------------------------------------------------------------------------
  8. Boolean TDeletePointCommand::IDeletePointCommand(TGeomView * itsGeometry, TPoint * tPt)
  9.     {
  10.     short        temp;                                                                                            // how to center the trash cans
  11.     Point        prev, next;                                                                                    // actual locations
  12.     short        maxSize;
  13.  
  14.     fGeom            =    itsGeometry;                                                                        // save the geometry
  15.     fCDocument    =    (TCFDFrontDocument *)fGeom->fCDocument;                        // get the document
  16.     fPoint            =    tPt;
  17.     fSide            =    (TBoundry *) ((TPointMatrix *) fCDocument->fPointMatrix)->GetCurrentBoundry();    // which boundry are we in?
  18.     HLock((Handle) this);
  19.     (TPointMatrix *) (fCDocument->fPointMatrix)->SetCornors(fPoint, &fInfo);
  20.     HUnlock((Handle) this);
  21.     fPoint->RememberPoint();
  22.     fRow            = ((TPointMatrix *) fCDocument->fPointMatrix)->GetRow();
  23.     fColumn        = ((TPointMatrix *) fCDocument->fPointMatrix)->GetColumn();
  24.     
  25.     if ((temp = ((TPointMatrix *) fCDocument->fPointMatrix)->ObsBaffInLine(fSide)) != 0)
  26.         {
  27.         char    msg[80];
  28.         
  29.         if (temp == 1)
  30.             sprintf(msg,"Obstacle");
  31.         else
  32.             sprintf(msg,"Baffle");
  33.         TWarning * tWarning;
  34.         TWindow    * aWindow;
  35.         
  36.         aWindow = NewTemplateWindow(kWarnMe, fCDocument);
  37.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  38.         tWarning->IWarning(9,msg);
  39.         tWarning->ShowWarning();
  40.         return false;
  41.         }
  42.         
  43.     fPrev    = fSide->GetAdjacentSegment(true, fPoint);                                        // get previous segment
  44.     fNext    = fSide->GetAdjacentSegment(false, fPoint);                                    // get previous segment
  45.     prev        = fPrev->fTrans;                                                                                // get location of next point
  46.     next        = fNext->fTrans;                                                                                // get location of last point
  47.         
  48.     if (fInfo.boundry == cTop || fInfo.boundry == cBottom)
  49.         {
  50.         lCent = 1;                                                                                                    // for centering the trash can
  51.         nCent = 3;
  52.         temp = next.h - prev.h;
  53.         if (temp < 10)
  54.             {
  55.             prev.h     -= abs(temp);
  56.             next.h += abs(temp);
  57.             }
  58.         }
  59.     else                                                                                                                // right or left boundry
  60.         {
  61.         lCent = 2;
  62.         nCent = 0;
  63.         temp = next.v - prev.v;
  64.         if (temp < 10)
  65.             {
  66.             prev.v     -= abs(temp);
  67.             next.v += abs(temp);
  68.             }
  69.         }
  70.     
  71.     if (fGeom->fMagnify == 0)
  72.         maxSize    = (short) (cGeomViewBorder+cMaxSize);
  73.     else
  74.         maxSize    = (short) ((cGeomViewBorder+cMaxSize) * fGeom->fMagnify);
  75.     trashL        = new TCTrash;                                                                        // left trash can closed
  76.     trashLO    = new TCTrash;                                                                        // left trash can open
  77.     trashL->ICTrash(prev,131,26,16,maxSize,lCent);
  78.     trashLO->ICTrash(prev,133,26,16,maxSize,lCent);
  79.     
  80.     trashR = new TCTrash;                                                                                // right trash can closed
  81.     trashRO = new TCTrash;                                                                            // right trash can open
  82.     trashR->ICTrash(next,131,26,16,maxSize,nCent);
  83.     trashRO->ICTrash(next,133,26,16,maxSize,nCent);
  84.     
  85.     fGeom->SetDragging(false);                                                                        // init dragging to false
  86.     ICommand (cDeleteSegCommand,fCDocument,fGeom,fGeom->GetScroller(true));
  87.     fConstrainsMouse = true;                                                                            // constrain the mouse
  88.     rightOn = leftOn = false;
  89.     saveDeleted = NULL;
  90.     return true;
  91.     }
  92.  
  93. // --------------------------------------------------------------------------------------------------
  94. //    Display the Lines
  95. // --------------------------------------------------------------------------------------------------
  96. void TDeletePointCommand::DisplayIt(Point trans, Point temp)
  97.     {
  98.     PenMode(srcXor);                                                                                    // pen mode to xor
  99.     
  100. //    Erase Boundry points and segment lines        
  101.     fPoint->Draw();                                                                                    // erase point
  102.     if (fInfo.above != NULL)                                                                            // is there a grid?
  103.         fInfo.above->DrawGrid(fPoint->fTrans);                                            // erase the grid lines
  104.         
  105.     fPoint->DrawSection(fInfo.left->fTrans);                                                // erase the left segment
  106.     fInfo.right->DrawSection(fPoint->fTrans);                                            // erase the right segment
  107.  
  108.     if (trashLO->InTheCan(trans))                                                                // over left can
  109.         {
  110.         leftOn = true;                                                                                    // set left open
  111.         trashLO->DrawCan();                                                                        // draw open can
  112.         if (rightOn)                                                                                        // was right open?
  113.             {    
  114.             trashR->DrawCan();                                                                        // close right
  115.             rightOn = false;                                                                            // set right closed
  116.             }
  117.         }
  118.     else if (trashRO->InTheCan(trans))                                                        // over right can?
  119.         {
  120.         rightOn = true;                                                                                    // set right open
  121.         trashRO->DrawCan();                                                                        // draw right open
  122.         if (leftOn)                                                                                            // was left open?
  123.             {
  124.             trashL->DrawCan();                                                                        // close left
  125.             leftOn = false;                                                                                // set left closed
  126.             }
  127.         }
  128.     else if (leftOn)                                                                                        // not in either can but left open
  129.         {
  130.         leftOn = false;                                                                                    // set left closed
  131.         trashL->DrawCan();                                                                            // draw left closed
  132.         }
  133.     else if (rightOn)                                                                                    // right open?
  134.         {
  135.         rightOn = false;                                                                                // set right closed
  136.         trashR->DrawCan();                                                                            // draw right closed
  137.         }
  138.  
  139.     fPoint->SetStart(temp.v,temp.h);                                                            // set fStart Point to new point
  140.  
  141. //    Redraw boundry points and segment lines
  142.     fPoint->DrawSection(fInfo.left->fTrans);                                                // draw the left segment
  143.     fInfo.right->DrawSection(fPoint->fTrans);                                            // draw the right segment
  144.  
  145.     if (fInfo.above != NULL)                                                                            // is there a grid?
  146.         fInfo.above->DrawGrid(fPoint->fTrans);                                            // draw the grid lines
  147.  
  148.     fPoint->Draw();                                                                                    // draw point
  149.     }
  150.  
  151. // --------------------------------------------------------------------------------------------------
  152. //    Do the command
  153. // --------------------------------------------------------------------------------------------------
  154. pascal void TDeletePointCommand::DoIt(void)
  155.     {
  156.     Point     temp;
  157.     Rect     can;
  158.     WallRecord nData;
  159.      
  160.     if (trashLO->InTheCan(fPoint->fTrans))                                                    // over left can
  161.         {
  162.         delRightSeg    = 1;                                                                                // deleting left segment
  163.         saveData        = ((TSegPoint *) fPoint)->GetData();                            // get data for this segment
  164.         saveType        = fPoint->GetSectionType();                                            // keep the section type
  165.         if (saveType != fNext->GetSectionType())                                            // are segment types same?
  166.             {                                                                                                    // no reset : redraw
  167.             fGeom->Select(fPoint,true,fSide);
  168.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  169.             ((TPointMatrix *) fCDocument->fPointMatrix)->SetSegment(fPoint,fSide,fNext->GetSectionType());
  170.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  171.             fGeom->UnSelect();
  172.             }
  173.         ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);    
  174.         saveDeleted = ((TPointMatrix *) fCDocument->fPointMatrix)->DeleteCurrent(fSide);
  175.         fPoint = NULL;
  176.         }
  177.     else if (trashRO->InTheCan(fPoint->fTrans))
  178.         {
  179.         delRightSeg    = 2;
  180.         saveData        = ((TSegPoint *) fNext)->GetData();                                // get data for this segment
  181.         saveType        = fNext->GetSectionType();
  182.         nData             = ((TSegPoint *) fPoint)->GetData();                            // get data for this segment
  183.         ((TSegPoint *) fNext)->SetData(nData);                                            // change data on next segment
  184.  
  185.         if (fPoint->GetSectionType() != saveType)
  186.             {
  187.             fGeom->Select(fNext,true,fSide);
  188.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  189.             ((TPointMatrix *) fCDocument->fPointMatrix)->SetSegment(fNext,fSide,fPoint->GetSectionType());
  190.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  191.             fGeom->UnSelect();
  192.             }
  193.         ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);    
  194.         saveDeleted = ((TPointMatrix *) fCDocument->fPointMatrix)->DeleteCurrent(fSide);
  195.         fPoint = NULL;
  196.         }
  197.     else
  198.         {
  199.         temp = fPoint->RetrievePoint();
  200.         this->DisplayIt(fPoint->fTrans,temp);
  201.         fGeom->Select(fPoint,false,fSide);
  202.         ((TPointMatrix *) fCDocument->fPointMatrix)->DoHighlight();
  203.         delRightSeg    = 0;
  204.         saveDeleted    = NULL;
  205.         }        
  206.     
  207.     can = trashL->GetRect();
  208.     HLock((Handle) this);
  209.     fGeom->InvalidRect(&can);
  210.     can = trashR->GetRect();
  211.     fGeom->InvalidRect(&can);
  212.     HUnlock((Handle) this);
  213.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();                // show number of segments
  214.     }
  215.         
  216. // --------------------------------------------------------------------------------------------------
  217. //    UnDo the command
  218. //        recreate the point & add it back in
  219. // --------------------------------------------------------------------------------------------------
  220. pascal void TDeletePointCommand::UndoIt(void)
  221.     {
  222.     if (delRightSeg == 0)
  223.         return;
  224.             
  225. //    Reset the data & wall types back to the original
  226.  
  227.     fGeom->Focus();
  228.     fPoint = ((TPointMatrix *) fCDocument->fPointMatrix)->AddLine(saveDeleted,fSide,fRow,fColumn);    
  229.     if (delRightSeg == 2)
  230.         {
  231.         ((TSegPoint *) fNext)->SetData(saveData);
  232.         if (saveType != fNext->GetSectionType())
  233.             {
  234.             fGeom->Select(fNext,true,fSide);
  235.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  236.             ((TPointMatrix *) fCDocument->fPointMatrix)->SetSegment(fNext,fSide,saveType);
  237.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  238.             fGeom->UnSelect();
  239.             }
  240.         }
  241.     else
  242.         {
  243.         if (saveType != fNext->GetSectionType())
  244.             {
  245.             fGeom->Select(fPoint,true,fSide);
  246.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  247.             ((TPointMatrix *) fCDocument->fPointMatrix)->SetSegment(fPoint,fSide,saveType);
  248.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  249.             fGeom->UnSelect();
  250.             }
  251.         }        
  252.  
  253.     ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);                        // point to the point
  254.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();                        // show number of segments
  255.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string return;
  256.     }
  257.     
  258. // --------------------------------------------------------------------------------------------------
  259. //    UnDo the command
  260. // --------------------------------------------------------------------------------------------------
  261. pascal void TDeletePointCommand::RedoIt(void)
  262.     {
  263.     WallRecord nData;
  264.      
  265.     fGeom->Focus();
  266.     if (delRightSeg == 1)                                                                                // over left can
  267.         {
  268.         if (saveType != fNext->GetSectionType())                                            // are segment types same?
  269.             {                                                                                                    // no reset : redraw
  270.             fGeom->Select(fPoint,true,fSide);
  271.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  272.             ((TPointMatrix *) fCDocument->fPointMatrix)->SetSegment(fPoint,fSide,fNext->GetSectionType());
  273.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  274.             fGeom->UnSelect();
  275.             }
  276.         ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);    
  277.         saveDeleted = ((TPointMatrix *) fCDocument->fPointMatrix)->DeleteCurrent(fSide);
  278.         fPoint = NULL;
  279.         }
  280.     else if (delRightSeg == 2)
  281.         {
  282.         nData             = ((TSegPoint *) fPoint)->GetData();                            // get data for this segment
  283.         ((TSegPoint *) fNext)->SetData(nData);                                            // change data on next segment
  284.  
  285.         if (fPoint->GetSectionType() != saveType)
  286.             {
  287.             fGeom->Select(fNext,true,fSide);
  288.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  289.             ((TPointMatrix *) fCDocument->fPointMatrix)->SetSegment(fNext,fSide,fPoint->GetSectionType());
  290.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoDrawSegment();
  291.             fGeom->UnSelect();
  292.             }
  293.         ((TPointMatrix *) fCDocument->fPointMatrix)->SetCurrent(fPoint);    
  294.         saveDeleted = ((TPointMatrix *) fCDocument->fPointMatrix)->DeleteCurrent(fSide);
  295.         fPoint = NULL;
  296.         }
  297.     }
  298.     
  299.     
  300. // --------------------------------------------------------------------------------------------------
  301. //    Track the Mouse
  302. // --------------------------------------------------------------------------------------------------
  303. pascal TCommand * TDeletePointCommand::TrackMouse(TrackPhase thePhase, VPoint * /*anchorPoint*/,
  304.     VPoint * /*previousPoint*/, VPoint * /*nextPoint*/, Boolean /*mouseDidMove*/)
  305.     {
  306.     if (!fGeom->IsDragging())                                                                        // starting the delete procedure?
  307.         {                                                                                                        // show trash cans
  308.         fGeom->lastCmd = 1;
  309.         fGeom->SetDragging(true);                                                                // turn dragging on
  310.         trashL->DrawCan();                                                                            // draw the trash cans
  311.         trashR->DrawCan();                                                                            // draw the trash cans
  312.         if (fGeom->fSPoint != NULL)                                                                // is there a selected point?
  313.             {
  314.             ((TPointMatrix *) fCDocument->fPointMatrix)->DoHighlight();        // unhighlight
  315.             fGeom->UnSelect();                                                                        // turn off selection
  316.             }
  317.         }
  318.     if (thePhase == trackRelease)
  319.         fGeom->SetDragging(false);
  320.  
  321.     return this;
  322.     }
  323.  
  324. // --------------------------------------------------------------------------------------------------
  325. //    Give user feedback on the mouse drag
  326. // --------------------------------------------------------------------------------------------------
  327. pascal void TDeletePointCommand::TrackFeedback(VPoint * /*anchorPoint*/,VPoint * nextPoint, 
  328.     Boolean /*turnItOn*/, Boolean mouseDidMove)
  329.     {
  330.     Point trans, thisPoint;
  331.     
  332.     fGeom->Focus();
  333.     if (mouseDidMove)                                                                                // got movement
  334.         {
  335.         trans = fGeom->ViewToQDPt(nextPoint);
  336.         thisPoint = AntiTransform(trans, fGeom->fMagnify);
  337.         this->DisplayIt(trans,thisPoint);
  338.         }
  339.     return;
  340.     }
  341.     
  342. // --------------------------------------------------------------------------------------------------
  343. //    Free the object
  344. // --------------------------------------------------------------------------------------------------
  345. pascal void TDeletePointCommand::Free(void)
  346.     {
  347.     delete trashL;
  348.     delete trashR;
  349.     inherited::Free();
  350.     }
  351.  
  352. // --------------------------------------------------------------------------------------------------
  353. //    Commit the command
  354. // --------------------------------------------------------------------------------------------------
  355. pascal void TDeletePointCommand::Commit(void)
  356.     {
  357.     short x, side;
  358.     TPoint * t;
  359.     
  360.     if (saveDeleted != NULL)
  361.         {
  362.         side = fSide->GetSide();
  363.         for (x = (short) saveDeleted->fSize; x > 0; x--)
  364.             {
  365.             t = (TPoint *) saveDeleted->At(x);
  366.             saveDeleted->Delete(t);
  367.             FreeIfObject(t);
  368.             }
  369.  
  370.         if (side == cLeft || side == cRight)                                                        // if on right or left delete the list
  371.             FreeIfObject(saveDeleted);
  372.         }
  373.     }
  374.